import { APIVoiceGetList } from "@/api/ApiSpeechModel"
import { GetVHuManModelListApi } from "@/api/vhuman"
import { computed, ref } from "vue"

export interface VoiceListProps {
    id: number
    user_id: number
    model: string
    name: string
    gender: string
    voice_name: string
    voice_style: string
    status: string
}

export interface RobotModelListProps {
    id: number
    name: string
    url: string
}

export default function useVoiceModel() {
    const modelOptions = ref({
        yunShanName: [
            {
                name: "Yunshan-v1"
            },
            {
                name: "Yunshan-v2"
            }
        ],
        vHumanName: [] as RobotModelListProps[],
        AU: {
            count: 0,
            list: [] as VoiceListProps[]
        },
        CHAT: {
            count: 0,
            list: [] as VoiceListProps[]
        },
        BARD: {
            count: 0,
            list: [] as VoiceListProps[]
        }
    })

    const getVoiceList = async () => {
        try {
            ;["AU", "CHAT", "BARD"].forEach(async (e) => {
                const { data } = await APIVoiceGetList({ model: e, page: 1 })
                // @ts-ignore
                modelOptions.value[e].list = data.list
                // @ts-ignore
                modelOptions.value[e].count = data.count
            })
        } catch (error) {
            console.error(error)
        }
    }

    const initRobotModelList = async (name?: string) => {
        try {
            const { data } = await GetVHuManModelListApi({ name })
            modelOptions.value.vHumanName = [].concat(data)
        } catch (error) {
            console.error(error)
        }
    }

    const allVoiceOptions = computed(() => {
        const allOptions = [...modelOptions.value.BARD.list, ...modelOptions.value.AU.list, ...modelOptions.value.CHAT.list]
        return allOptions
    })

    return {
        modelOptions,
        allVoiceOptions,
        getVoiceList,
        initRobotModelList
    }
}
